
<template>
  <div>
   <el-row>
      <el-col :span="8">
        <category-common
        @handler="handlerMessage"
        >
        </category-common>
      </el-col>

     <el-col :span="16">
       <el-row>
         <el-col :span="8"  style="min-width:150px">
           <el-input  placeholder="搜索名称"></el-input>
         </el-col>
         <el-col :span="1" style="min-width: 80px;margin-left: 10px">
           <el-button @click="findAll">查询</el-button>
         </el-col>
         <el-col :span="1" style="min-width: 80px">
           <el-button @click="currentOperator('save')">新增</el-button>
         </el-col>
       </el-row>
       <el-row style="margin-top: 10px">
         <el-table
           :data="tableData"
           border
           :header-cell-style="{'text-align':'center'}"
           style="width: 100%;">

           <el-table-column
             align="center"
             prop="attr_group_id"
             label="分组id"
           >
           </el-table-column>

           <el-table-column
             align="center"
             prop="attr_group_name"
             label="组名"
           >
           </el-table-column>

           <el-table-column
             align="center"
             prop="sort"
             label="排序"
           >
           </el-table-column>

           <el-table-column
             align="center"
             prop="descript"
             label="描述"
           >
           </el-table-column>

           <el-table-column
             align="center"
             prop="icon"
             label="组图标"
           >
           </el-table-column>

           <el-table-column
             align="center"
             prop="catelog_id"
             label="所属分类id"
           >
           </el-table-column>

           <el-table-column
             align="center"
             label="操作">
             <template slot-scope="rows">
               <el-button  @click="currentOperator('update',rows.row)">修改</el-button>
               <el-button @click="currentOperator('delete',rows.row)">删除</el-button>
             </template>
           </el-table-column>
         </el-table>
       </el-row>

<!--       <el-pagination-->
<!--         align="center"-->
<!--         @size-change="handleSizeChange"-->
<!--         @current-change="handleCurrentChange"-->
<!--         :current-page="query.page"-->
<!--         :page-sizes="[1, 5, 10, 20]"-->
<!--         :page-size="query.size"-->
<!--         layout="total, sizes, prev, pager, next, jumper"-->
<!--         :total="total">-->
<!--       </el-pagination>-->


       <pmsattrgroup-save
         :dialogShow="dialogShow"
         :pmsattrgroupFrom="pmsattrgroupFrom"
         @handler="handlerMessage"
       >
       </pmsattrgroup-save>

     </el-col>
   </el-row>

  </div>
</template>
<script>

import pmsattrgroupApi from '@/api/product/PmsAttrGroup'
import pmsattrgroupSave from './PmsAttrGroup-save'
import categoryCommon from '../common/category'

export default {
  name: "pmsattrgroup",
  components:{
    pmsattrgroupSave,
    categoryCommon
  },
  data() {
     return {
       dialogShow:false,
       total:0,
       tableData:[],
       pmsattrgroupFrom:{
       },
       query:{
         page:0,
         size:5,
       } ,
     }
  },
  methods:{
    handlerMessage(code,message){
        if (code=="close"){
           this.dialogShow=false
           //清空form的数据
           this.pmsattrgroupFrom={}
        }else if(code=="open"){
          this.dialogShow=true
        }else if(code=="save"){
           this.save(message)
        }else if(code=="update"){
          this.update(message)
        }else if(code=="changeNode"){
          this.findGroupByCatId(message)
        }
    },
    currentOperator(code,obj){
      if (code=="save"){
         this.dialogShow=true
      }else if (code=="update"){
        this.findById(obj.attr_group_id)
      }else if (code=="delete"){
         //删除单个
         this.delete(obj.attr_group_id)
      }

    },
    findGroupByCatId(id){
       pmsattrgroupApi.findGroupByCatId({"catelog_id":id}).then(res=>{
         if (res.code==200){
           this.tableData=res.list

         }else {
           this.$message.error(res.message)
         }
       })
    },
    search(){

    },
    findAll(){
      pmsattrgroupApi.findAll(this.query).then(res=>{
        if (res.code==200){
          this.tableData=res.list
          this.total=res.total
        }else {
            this.$message.error(res.message)
        }
      })
    },
    findById(id){
      pmsattrgroupApi.findById({"attr_group_id":id}).then(res=>{
        if (res.code==200){
          this.pmsattrgroupFrom=res.model
          this.dialogShow=true
        }else {
          this.$message.error(res.message)
        }
      })

    },
    save(obj){
      pmsattrgroupApi.save(obj).then(res=>{
         if (res.code==200){
            this.$message.success(res.message)
            this.findAll()
         }else {
           this.$message.error(res.message)
         }
      })
    },
    update(obj){
      pmsattrgroupApi.update(obj).then(res=>{
        if (res.code==200){
          this.$message.success(res.message)
          this.findAll()
        }else {
          this.$message.error(res.message)
        }
      })
    },
    delete(ids){
      this.$confirm('是否删除?', '警告!', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        pmsattrgroupApi.delete(ids).then(res=>{
          if (res.code==200){
            this.$message.success(res.message)
            this.findAll()
          }else {
            this.$message.error(res.message)
          }
        })
      }).catch(() => {
          //取消后的逻辑
      });

    },
    handleSizeChange(size){
       this.query.size=size
       this.findAll()
    },
    handleCurrentChange(page){
      this.query.page=page
      this.findAll()
    },

  },
  created() {
    //this.findAll()
  }
}
</script>

<style lang="less" scoped>
</style>

